{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "from scipy import io as sio\n",
    "import pickle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "from matplotlib import use as mpl_use"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Using matplotlib backend: QtAgg\n"
     ]
    }
   ],
   "source": [
    "%matplotlib"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# data 2: (1,1), (0,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "mpl_use('svg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.figure()\n",
    "ax = plt.gca()\n",
    "for j in range(50):\n",
    "    if (os.path.exists(\"data/GBZ_data_1/y_major_%d.pkl\"%(j))):\n",
    "        with open(\"data/GBZ_data_1/y_major_%d.pkl\"%(j), \"rb\") as fp:\n",
    "            all_segments = pickle.load(fp)\n",
    "        for seg in all_segments:\n",
    "            ax.plot(seg[:,0].real, seg[:,0].imag, 'b.')\n",
    "        # plt.pause(0.01)\n",
    "        # err_flag = int(input(\"%d\"%(j)))\n",
    "        # if(err_flag):\n",
    "        #     print(\"non GBZ point: %d\"%(j))\n",
    "    else:\n",
    "        print(\"solution error: %d\"%(j))\n",
    "ax.set_xlabel(\"$\\\\mathrm{Re}(E)$\")\n",
    "ax.set_ylabel(\"$\\\\mathrm{Im}(E)$\")\n",
    "ax.set_xlim([-10,10])\n",
    "ax.set_ylim([-3,3])\n",
    "plt.savefig(\"Figures/y_major_1.svg\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "info = sio.loadmat(\"data/GBZ_info_1.mat\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'__header__': b'MATLAB 5.0 MAT-file Platform: posix, Created on: Sat Sep  2 19:06:52 2023', '__version__': '1.0', '__globals__': [], 'model_params': array([[3.+0.j, 3.+0.j, 4.+0.j, 4.+0.j, 0.+1.j, 0.+1.j]]), 'phi1_list': array([[0.06159986, 0.12319971, 0.18479957, 0.24639942, 0.30799928,\n",
      "        0.36959914, 0.43119899, 0.49279885, 0.5543987 , 0.61599856,\n",
      "        0.67759842, 0.73919827, 0.80079813, 0.86239798, 0.92399784,\n",
      "        0.9855977 , 1.04719755, 1.10879741, 1.17039726, 1.23199712,\n",
      "        1.29359698, 1.35519683, 1.41679669, 1.47839654, 1.5399964 ,\n",
      "        1.60159625, 1.66319611, 1.72479597, 1.78639582, 1.84799568,\n",
      "        1.90959553, 1.97119539, 2.03279525, 2.0943951 , 2.15599496,\n",
      "        2.21759481, 2.27919467, 2.34079453, 2.40239438, 2.46399424,\n",
      "        2.52559409, 2.58719395, 2.64879381, 2.71039366, 2.77199352,\n",
      "        2.83359337, 2.89519323, 2.95679309, 3.01839294, 3.0799928 ]]), 'phi2_list': array([[0.06159986, 0.12319971, 0.18479957, 0.24639942, 0.30799928,\n",
      "        0.36959914, 0.43119899, 0.49279885, 0.5543987 , 0.61599856,\n",
      "        0.67759842, 0.73919827, 0.80079813, 0.86239798, 0.92399784,\n",
      "        0.9855977 , 1.04719755, 1.10879741, 1.17039726, 1.23199712,\n",
      "        1.29359698, 1.35519683, 1.41679669, 1.47839654, 1.5399964 ,\n",
      "        1.60159625, 1.66319611, 1.72479597, 1.78639582, 1.84799568,\n",
      "        1.90959553, 1.97119539, 2.03279525, 2.0943951 , 2.15599496,\n",
      "        2.21759481, 2.27919467, 2.34079453, 2.40239438, 2.46399424,\n",
      "        2.52559409, 2.58719395, 2.64879381, 2.71039366, 2.77199352,\n",
      "        2.83359337, 2.89519323, 2.95679309, 3.01839294, 3.0799928 ]])}\n"
     ]
    }
   ],
   "source": [
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = sio.loadmat(\"data/OBC_numerical_1.mat\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n"
     ]
    }
   ],
   "source": [
    "with open(\"data/GBZ_data_4/x_major_32.pkl\", \"rb\") as fp:\n",
    "    all_segments = pickle.load(fp)\n",
    "print(len(all_segments))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "eigv = data['eigv'].flatten()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "# mpl_use('QtAgg')\n",
    "mpl_use('svg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "ax.plot(eigv.real, eigv.imag, 'k.')\n",
    "ax.set_xlabel(\"$\\\\mathrm{Re}(E)$\")\n",
    "ax.set_ylabel(\"$\\\\mathrm{Im}(E)$\")\n",
    "ax.set_xlim([-10,10])\n",
    "ax.set_ylim([-3,3])\n",
    "# plt.show()\n",
    "fig.savefig(\"Figures/OBC_spectrum_1_50x50.svg\")\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.16"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
